package cake.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cake.dao.UserDao;
import cake.dao.impl.UserDaoImpl;
import cake.entity.User;
@WebServlet("/register.html")
public class RegisterServlet extends HttpServlet{
	
	private UserDao userDao=new UserDaoImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String userName=req.getParameter("username");
		String passWord=req.getParameter("password");
		String email=req.getParameter("email");
		User user=new User(0, userName, passWord, email, true);		
		userDao.addUser(user);
		resp.sendRedirect("login.jsp");
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.getRequestDispatcher("register.jsp").forward(req, resp);
	}
}
